package util;


public class Reference {
	private Object value;
	private Type type;
	private String name;
	
	public Type getType() {
		return type;
	}
	
	public String getName() {
		return name;
	}

	public String getTypename(){
		return type.toString();
	}

	public Reference(String name, Type type) {
		this.name = name;
		this.type = type;
		
		if(type.isArray()){
			value = new Result[type.getArraySize()];
		}
	}
	
	public Reference(Attribute attribute){
		this(attribute.getName(), attribute.getType());
	}

	public Object getValue() {
		if(isArray())
			return (Result[])value;
		return ((Result)value).getValue();
	}

	public boolean isArray() {
		return type.isArray();
	}

	public int getArraySize() {
		return type.getArraySize();
	}

	public void setValue(Result value) {
		this.value = value;
	}
	
	public String toString() {
		return this.name+" "+this.type+" "+((isArray())?"(Array)":"")+" "+this.value;
	}
}
